#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string convert(string s, int numRows) {
        if (numRows == 1) return s;
        int n = s.size();
        string ret;
        for (int i = 0; i < numRows; i++)
        {
            int down_past = (numRows - i) * 2 - 2;
            int up_past = (i + 1) * 2 - 2;
            string str;

            int j = i;
            if (up_past == 0) str += s[0];
            while (j < n)
            {
                if (up_past != 0) str += s[j];
                j += down_past;
                if (j < n && down_past != 0) str += s[j];
                j += up_past;
            }

            ret += str;
        }
        return ret;
    }
};